package VacationHomework.LeetCode;

import com.sun.org.apache.regexp.internal.RE;

public class Num13 {
    public int romanToInt(String s) {
        int ret=0;
        char a=s.charAt(0);
        int prev=get(a);
        for (int i = 1; i < s.length()-1; i++) {
            char b=s.charAt(i);
            int cur=get(b);
            if(prev>=cur){
                ret+=prev+cur;
            }else {
                ret+=(-prev)+cur;
            }
            prev=cur;
        }
         ret+=get( s.charAt(s.length()-1));
         return ret;
    }

    private int get(char c) {
        switch (c){
            case 'I':
                return 1;
            case 'V':
                return 5;

            case 'X':
                return 10;

            case 'L':
                return 50;

            case 'C':
                return 100;

            case 'D':
                return 500;

            case 'M':
                return 1000;

        }
        return 1;
    }
}
